package com.squapsource.project_euler.utils;

import java.util.ArrayList;
import java.util.List;

public class PrimesUtility {
	
	public static List<Long> getPrimesUpToMax(long maxNum) {
		List<Long> primes = new ArrayList<Long>();
		primes.add(2L);
		for (long i=3; i <maxNum; i+=2)
		{
			if (isPrime(i, primes))
			{
				primes.add(i);
				//System.out.println(i);
			}
		}
		return primes;
	}
	
	public static boolean isPrime(long testNum, List<Long> primes) {
		for (Long prime : primes) {
			if (prime > Math.sqrt(testNum))
				return true;
			if (testNum % prime == 0)
				return false;
		}
		return true;
	}
}
